package com.mattcofer.cartoonwidget;

import com.mattcofer.cartoonwidget.CartoonProvider.CartoonsColumns;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.RemoteViews;

public class ViewCartoon extends Activity {
    private static final String[] PROJECTION_CARTOONS = new String[] {
    	CartoonsColumns.URI, //URI of the image in the internal media library
    };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent callingIntent = this.getIntent();
		Uri imageUri = null;
		Uri appWidgetUri = null;
		
		if (callingIntent!=null)
		{
			imageUri = callingIntent.getData();
			appWidgetUri = Uri.parse(callingIntent.getStringExtra("appWidgetUri"));
		}
		
		Log.d("CartoonWidget", ".ViewCartoon$onCreate Image Uri: "+imageUri);
		
		//Build the updated widget
		RemoteViews	updateViews = null;
		updateViews = new RemoteViews(this.getPackageName(), R.layout.main);
		updateViews.setImageViewUri(R.id.image, imageUri);
		
		//Update the widget (this removes the highlighting from the image border)
    	ComponentName thisWidget = new ComponentName(this, CartoonWidget.class);
    	AppWidgetManager manager = AppWidgetManager.getInstance(this);
    	manager.updateAppWidget(thisWidget, updateViews);

    	//Kick off the internal image viewer
    	startActivity(new Intent(Intent.ACTION_VIEW, imageUri));
    	
    	//End self
		this.finish();
    }
}